package Demo1;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-07-09
 * Time: 9:59
 */
public class Test {
    public static void main(String[] args) {

    }
    public List<List<Integer>> generate(int numRows) {//杨辉三角
        List<List<Integer>> list = new ArrayList<>();
        //准备工作
        ArrayList<Integer> tmp = new ArrayList<>();
        tmp.add(1);
        list.add(tmp);

        for (int i = 1; i < numRows; i++) {
            //开始
            tmp = new ArrayList<>();
            tmp.add(1);
            for (int j = 1; j < i; j++) {
                //中间
                tmp.add(list.get(i - 1).get(j) + list.get(i - 1).get(j - 1));
            }
            //结尾
            tmp.add(1);
            list.add(tmp);
        }
        return list;
    }
    public static void main10(String[] args) {
        List<List<Integer>> list = new ArrayList<>();
//        System.out.println(list);
//        list.add(new ArrayList<>());
//        list.add(new ArrayList<>());
        ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        ArrayList<Integer> list2 = new ArrayList<>();
        list2.add(3);
        list2.add(4);
        list.add(list1);
        list.add(list2);
        System.out.println(list);
    }
    public static void main9(String[] args) {
        //需求:删除str1里面与str2相同的字符,并将结果存储到ArrayList里面
        String str1 = "welcome to bit";
        String str2 = "come";
        ArrayList<Character> list = new ArrayList<>();//创建顺序表用来存储字符
        for (int i = 0; i < str1.length(); i++) {
            if(!str2.contains(str1.charAt(i) + "")){//技巧
                list.add(str1.charAt(i));
            }
        }
        System.out.println(list);
    }
    public static void main8(String[] args) {
        ArrayList<Integer> test = new ArrayList<>(5);
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        //遍历顺序表的方法
        //for-循环遍历
        for (int i = 0; i < test.size(); i++) {
            System.out.print(test.get(i) + " ");
        }
        System.out.println();
        //for-each-循环遍历
        for (int x:test) {
            System.out.print(x + " ");
        }
        System.out.println();
        //使用 Iterator迭代器打印
        Iterator<Integer> it1 = test.iterator();
        while(it1.hasNext()){
            System.out.print(it1.next() + " ");
        }
        System.out.println();
        //使用 ListIterator迭代器打印 拓展
        ListIterator<Integer> it2 = test.listIterator();
        while(it2.hasNext()){
            System.out.print(it2.next() + " ");
        }
        System.out.println();
        //使用 ListIterator迭代器打印 拓展
        ListIterator<Integer> it3 = test.listIterator(test.size());
        while(it3.hasPrevious()){
            System.out.print(it3.previous() + " ");
        }
        System.out.println();
    }
    public static void main7(String[] args) {
        ArrayList<Integer> test = new ArrayList<>(5);
        test.add(1);
        test.add(3);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test.indexOf(new Integer(5)));
        System.out.println(test.lastIndexOf(new Integer(3)));
        List<Integer> list = test.subList(1,4);
        System.out.println(list);
        list.set(1,99999);
        System.out.println(list);
        System.out.println(test);
    }
    public static void main6(String[] args) {
        ArrayList<Integer> test = new ArrayList<>(5);
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test);
//        test.remove(1);
//        test.remove(1);
        test.remove(new Integer(5));
        System.out.println(test);
        System.out.println(test.get(3));
        test.set(3,12222);
        System.out.println(test);
        test.clear();
        System.out.println(test);
    }
    public static void main5(String[] args) {
        ArrayList<Integer> test = new ArrayList<>(5);
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test);
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.addAll(test);
        System.out.println(list);
    }
    public static void main4(String[] args) {
        ArrayList<Integer> test = new ArrayList<>(5);
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        System.out.println(test);
        test.add(1,100);
        System.out.println(test);
    }
    public static void main3(String[] args) {
        ArrayList<Integer> test = new ArrayList<>(5);
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        ArrayList<Integer> list = new ArrayList<>(test);
        list.add(100);
        list.add(101);
        list.add(102);
        for (int i = 0; i < test.size(); i++) {
            System.out.print(test.get(i) + " ");
        }
        System.out.println();
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();

    }
    public static void main2(String[] args) {
        //带参构造：传值指定数组大小长度
        ArrayList<Integer> test = new ArrayList<>(0);
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
//        System.out.println(0 >> 1);
        for (int i = 0; i < test.size(); i++) {
            System.out.print(test.get(i) + " ");
        }
        System.out.println();
    }
    public static void main1(String[] args) {
        //无参构造方法
        ArrayList<Integer> test = new ArrayList<Integer>();
        test.add(1);
        test.add(2);
        test.add(3);
        test.add(4);
        test.add(5);
        for (int i = 0; i < test.size(); i++) {
            System.out.print(test.get(i) + " ");
        }
        System.out.println();
    }
}
